﻿using System;
using Newtonsoft.Json;
using System.Text;
namespace Fonour.Utility
{
    public class ByteConvertHelper
    {
        public static byte[] Object2Bytes(object obj)
        {
            string json = JsonConvert.SerializeObject(obj);
            return Encoding.UTF8.GetBytes(json); ;
        }

        public static object Bytes2Object(byte[] buffer)
        {
            string json = Encoding.UTF8.GetString(buffer);
            return JsonConvert.DeserializeObject(json);
        }

        public static T Bytes2Object<T>(byte[] buffer)
        {
            string json = Encoding.UTF8.GetString(buffer);
            return JsonConvert.DeserializeObject<T>(json);
        }
    }
}
